<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('地址列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-grid"></i> 地址
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
				<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
				<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
			</div>
		</div>
		<div class="ui-layout-content">
			<div id="tree" class="ztree"></div>
		</div>
	</div>
</div>

<div class="ui-layout-center">
	<div class="tabs-container">
		<ul class="nav nav-tabs">
			<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 集中器数据</a>
			</li>
			<li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">阀门数据</a>
			</li>
			<li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="false">热表数据</a>
			</li>
			<li class=""><a data-toggle="tab" href="#tab-4" aria-expanded="false">室温采集器数据</a>
			</li>
		</ul>
		<div class="tab-content">
			<div id="tab-1" class="tab-pane active">
				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table"></table>
				</div>
			</div>
			<div id="tab-2" class="tab-pane">
				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table1"></table>
				</div>
			</div>
			<div id="tab-3" class="tab-pane">
				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table2"></table>
				</div>
			</div>
			<div id="tab-4" class="tab-pane">
				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table3"></table>
				</div>
			</div>
		</div>
	</div>
	</div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />

<script th:inline="javascript">

	var datas = [[${@dict.getType('equipment_status')}]];

	$(function() {
		var panehHidden = false;
		if ($(this).width() < 769) {
			panehHidden = true;
		}
		$('body').layout({ initClosed: panehHidden, west__size: 200 });
		queryBaseSubscriberTree();
		queryCalorimeterData(0);
		queryTempData(0);
		queryConcentratorData(0);
		queryValveData(0);
	});
	function queryCalorimeterData(subscriberId) {
		var url = ctx + "module/calorimeter/data/list"
		if(subscriberId != 0){
			url = url + "?subscriberId="+subscriberId;
		}
		$('#bootstrap-table2').bootstrapTable('destroy');
		$('#bootstrap-table2').bootstrapTable({
			url: url,
						sortOrder: "desc",
						modalName: "热表信息",
						contentType: "application/x-www-form-urlencoded",
						method: 'post',
						cache: false,
						pagination: true,
						pageSize: 10,
						pageList: [10, 25, 50],
						sidePagination: "server",
						columns: [
							{
								field: 'calorimeterId',
								title: '热表ID',
								formatter: function (value, row, index) {
									return '<a href="javascript:void(0)" onclick="detailCalorimeter(\'' + row.calorimeterId + '\')">' + value + '</a>';
								}
							},
							{
								field: 'calorimeterType.typeName',
								title: '热表型号'
							},
							{
								field: 'concentratorId',
								title: '采集器'
							},
							{
								field: 'installTime',
								title: '安装时间'
							},
							{
								field: 'installAddress',
								title: '安装地址'
							},
							{
								field: 'installUser',
								title: '安装人'
							},
							{
								field: 'factory.factoryName',
								title: '厂商名称'
							},
							{
								field: 'factory.factoryCode',
								title: '厂商代码'
							},
							{
								field: 'status',
								title: '设备状态',
								formatter: function (value, row, index) {
									return $.table.selectDictLabel(datas, value);
								}
							}]
					})
			;
	}

	function queryValveData(subscriberId) {
		var url = ctx + "module/valve/data/list"
		if(subscriberId != 0){
			url = url + "?subscriberId="+subscriberId;
		}
		$('#bootstrap-table1').bootstrapTable('destroy');
		$('#bootstrap-table1').bootstrapTable({
			url: url,
						sortOrder: "desc",
						modalName: "阀门信息",
						contentType: "application/x-www-form-urlencoded",
						method: 'post',
						cache: false,
						pagination: true,
						sidePagination: "server",
						columns: [
							{
								field: 'valveId',
								title: '阀门ID',
								formatter: function (value, row, index) {
									return '<a href="javascript:void(0)" onclick="detailValve(\'' + row.valveId + '\')">' + value + '</a>';
								}
							},
							{
								field: 'valveType.typeName',
								title: '阀门型号'
							},
							{
								field: 'concentratorId',
								title: '采集器'
							},
							{
								field: 'installTime',
								title: '安装时间'
							},
							{
								field: 'installAddress',
								title: '安装地址'
							},
							{
								field: 'installUser',
								title: '安装人'
							},
							{
								field: 'factory.factoryName',
								title: '厂商名称'
							},
							{
								field: 'factory.factoryCode',
								title: '厂商代码'
							},
							{
								field: 'status',
								title: '设备状态',
								formatter: function (value, row, index) {
									return $.table.selectDictLabel(datas, value);
								}
							},
							{
								field: 'aperture',
								title: '阀门开度'
							}]
					})
			;
	}
	function queryTempData(subscriberId) {
		var url = ctx + "module/temp/list"
		if(subscriberId != 0){
			url = url + "?subscriberId="+subscriberId;
		}
		$('#bootstrap-table3').bootstrapTable('destroy');
		$('#bootstrap-table3').bootstrapTable({
			url: url,
						sortOrder: "desc",
						modalName: "室温采集器信息",
						contentType: "application/x-www-form-urlencoded",
						method: 'post',
						cache: false,
						pagination: true,
						sidePagination: "server",
						columns: [
							{
								field: 'brtId',
								title: '室温采集器ID',
								formatter: function (value, row, index) {
									return '<a href="javascript:void(0)" onclick="detailTemp(\'' + row.valveId + '\')">' + value + '</a>';
								}
							},
							{
								field: 'brtName',
								title: '室温采集器型号'
							},

							{
								field: 'installAddress',
								title: '安装地址'
							},
							{
								field: 'brtUser',
								title: '用户'
							},
							{
								field: 'brtCurrent',
								title: '电流'
							},
							{
								field: 'brtVoltage',
								title: '电压'
							},
							{
								field: 'brtTemp',
								title: '温度'
							},
							{
								field: 'brtHumidity',
								title: '湿度'
							},
							{
								field: 'acquisitionTime',
								title: '采集时间'
							},
							{
								field: 'factory.factoryName',
								title: '厂商名称'
							},
							{
								field: 'factory.factoryCode',
								title: '厂商代码'
							}
						]

					})
		;
	}
	function queryConcentratorData(subscriberId) {
		var url = ctx + "module/concentrator/data/list"
		if(subscriberId != 0){
			url = url + "?subscriberId="+subscriberId;
		}
		$('#bootstrap-table').bootstrapTable('destroy');
		$('#bootstrap-table').bootstrapTable({
			url: url,
						sortOrder: "desc",
						modalName: "集中器信息",
						contentType: "application/x-www-form-urlencoded",
						method: 'post',
						cache: false,
						pagination: true,
						sidePagination: "server",
						columns: [
							{
								field: 'concentratorId',
								title: '集中器ID',
								formatter: function(value, row, index) {
									return '<a href="javascript:void(0)" onclick="detailConcentrator(\'' + row.concentratorId + '\')">' + value + '</a>';
								}
							},
							{
								field: 'concentratorType.typeName',
								title: '集中器型号'
							},

							{
								field: 'installTime',
								title: '安装时间'
							},
							{
								field: 'installAddress',
								title: '安装地址'
							},
							{
								field: 'installUser',
								title: '安装人'
							},
							{
								field: 'factory.factoryName',
								title: '厂商名称'
							},
							{
								field: 'factory.factoryCode',
								title: '厂商代码'
							},
							{
								field: 'status',
								title: '设备状态',
								formatter: function(value, row, index) {
									return $.table.selectDictLabel(datas, value);
								}
							}]

					})

	}

	function queryBaseSubscriberTree()
	{
		var url = ctx + "module/subscriber/treeData";
		var options = {
			url: url,
			expandLevel: 2,
			onClick : zOnClick
		};
		$.tree.init(options);

		function zOnClick(event, treeId, treeNode) {
			queryConcentratorData(treeNode.id);
			queryValveData(treeNode.id);
			queryTempData(treeNode.id);
			queryCalorimeterData(treeNode.id);
		}
	}

	$('#btnExpand').click(function() {
		$._tree.expandAll(true);
		$(this).hide();
		$('#btnCollapse').show();
	});

	$('#btnCollapse').click(function() {
		$._tree.expandAll(false);
		$(this).hide();
		$('#btnExpand').show();
	});

	$('#btnRefresh').click(function() {
		queryBaseSubscriberTree();
	});

	/* 数据展示 */
	function detailCalorimeter(calorimeterId) {
		var url = ctx + 'module/calorimeter/read/' + calorimeterId;
		$.modal.openTab("热表数据", url);
	}
	/* 集中器数据 */
	function detailConcentrator(concentratorId) {
		var url = ctx + 'module/concentrator/record/' + concentratorId;
		$.modal.openTab("集中器数据", url);

	}
	/* 数据展示 */
	function detailTemp(brtId) {
		var url = ctx + 'module/temp/record/' + brtId;
		$.modal.openTab("室温采集器数据", url);
	}
	/* 阀门数据 */
	function detailValve(valveId) {
		var url = ctx + 'module/valve/record/' + valveId;
		$.modal.openTab("阀门数据", url);
	}
</script>
</body>
</html>